﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.IO;

namespace PFAGame
{
    class StoryMenuScreen : MenuScreen
    {
        #region Initialization

        public StoryMenuScreen()
            : base("Story Mode")
        {
            // Create our menu entries.
            MenuEntry continueGameMenuEntry = new MenuEntry("Continue");
            MenuEntry newGameMenuEntry = new MenuEntry("New Game");
            MenuEntry backMenuEntry = new MenuEntry("Back");

            // Hook up menu event handlers.
            continueGameMenuEntry.Selected += StoryGameMenuEntrySelected;
            newGameMenuEntry.Selected += ArcadeGameMenuEntrySelected;
            backMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(continueGameMenuEntry);
            MenuEntries.Add(newGameMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }

        #endregion

        #region Handle Input

        void StoryGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            FileInfo fiSpec = new FileInfo("save_Spécialiste_PLAYERNAME.xml");
            FileInfo fiBour = new FileInfo("save_Bourrin_PLAYERNAME.xml");

            if (fiSpec.Exists == true && fiBour.Exists == false)
                LoadingScreen.Load(ScreenManager.Singleton, true, e.PlayerIndex, new GameplayScreen(null, e_class.SPECIALISTE, e_GameMode.STORY, 1, -1));
            else if (fiSpec.Exists == false && fiBour.Exists == true)
                LoadingScreen.Load(ScreenManager.Singleton, true, e.PlayerIndex, new GameplayScreen(null, e_class.BOURRIN, e_GameMode.STORY, 1, -1));
            else if (fiSpec.Exists == true && fiBour.Exists == true)
            {
                if (fiSpec.LastWriteTime > fiBour.LastWriteTime)
                    LoadingScreen.Load(ScreenManager.Singleton, true, e.PlayerIndex, new GameplayScreen(null, e_class.SPECIALISTE, e_GameMode.STORY, 1, -1));
                else
                    LoadingScreen.Load(ScreenManager.Singleton, true, e.PlayerIndex, new GameplayScreen(null, e_class.BOURRIN, e_GameMode.STORY, 1, -1));
            }
        }

        void ArcadeGameMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.AddScreen(new NewStoryGameMenuScreen(), e.PlayerIndex);
        }

        #endregion
    }
}
